home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / manual / examples / select.c < prev    next >
C/C++ Source or Header  |  1994-02-16  |  664b  |  33 lines

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5.  
  6. int 
  7. input_timeout (int filedes, unsigned int seconds)
  8. {
  9.   fd_set set;
  10.   struct timeval timeout;
  11.  
  12.   /* Initialize the file descriptor set. */
  13.   FD_ZERO (&set);
  14.   FD_SET (filedes, &set);
  15.  
  16.   /* Initialize the timeout data structure. */
  17.   timeout.tv_sec = seconds;
  18.   timeout.tv_usec = 0;
  19.  
  20.   /* @code{select} returns 0 if timeout, 1 if input available, -1 if error. */
  21.   return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
  22.                      &set, NULL, NULL,
  23.                      &timeout));
  24. }
  25.  
  26. int
  27. main (void)
  28. {
  29.   fprintf (stderr, "select returned %d.\n",
  30.        input_timeout (STDIN_FILENO, 5));
  31.   return 0;
  32. }
  33.